package com.example.hello_world;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import com.example.hello_world.model.Calculator;
import com.example.hello_world.model.CalculatorImpl;

public class MyActivity extends Activity implements View.OnClickListener {
    /**
     * Called when the activity is first created.
     */

    private Calculator calculator = new CalculatorImpl();

    EditText editTextFirst;
    EditText editTextSecond;
    EditText resultEditText;

    Button button;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        editTextFirst = (EditText) findViewById(R.id.editText);
        editTextSecond = (EditText) findViewById(R.id.editText1);
        resultEditText = (EditText) findViewById(R.id.editText2);

        button = (Button) findViewById(R.id.button);

        button.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        int firstNum = Integer.parseInt(editTextFirst.getText().toString());
        int secondNum = Integer.parseInt(editTextSecond.getText().toString());
        int result = calculator.add(firstNum, secondNum);
        resultEditText.setText(Integer.toString(result));
    }
}
